<?php
    $isFirstLevel = empty($menu[0]['Category']['parent_id']) ? true : false;
    
    $params = $this->params;
?>
<ul class="menu">

    <? if ($isFirstLevel): ?>
    <li>
        <? if ($params->controller == 'kalkulator'): ?>
            <strong>Kalkulator</strong>
        <? else: ?>
            <?= $this->Html->link('Kalkulator', '/kalkulator') ?>
        <? endif ?>
    </li>
    <? endif ?>

    <? foreach ($menu as $item): ?>
    <?php
        $categoryId   = $item['Category']['id'];
        $categoryName = $item['Category']['name'];
        $categoryKey  = $item['Category']['key'];
        $children     = $item['CategoryChildren'];
    ?>
    <li<?= empty($children) ? '' : ' class="sub"' ?>>
        <? if (
            $params->controller   == 'kategorije' && 
            $params->action       == 'index' &&
            !empty($params->pass) &&
            $params->pass[0]      == $categoryId
        ): ?>
            <strong><?= $categoryName ?></strong>
        <? else: ?>
            <?= $this->Html->link($categoryName, '/'.URL_SEO_PREFIX.'/' . $categoryId . '/' . $categoryKey) ?>
        <? endif ?>
        <? if (! empty($children)): ?>
            <?= $this->element('menu', array('menu' => $children)) ?>
        <? endif ?>
    </li>
    <? endforeach ?>
    
    <? if ($isFirstLevel): ?>
    <li>
        <? if ($params->controller == 'kontakt'): ?>
            <strong>Kontakt</strong>
        <? else: ?>
            <?= $this->Html->link('Kontakt', '/kontakt') ?>
        <? endif ?>
    </li>
    <? endif ?>
</ul>